Skip to content

Conversation

Copy link

Copilot AI commented Oct 5, 2025

Fix: CLI logs wrong path for utils file during init

Fixes the issue where the CLI incorrectly logs the default path for the utils file even when it's installed at a custom location.

Problem

When initializing shadcn-svelte with a custom path for the utils file (e.g., $lib/features/shared/components/_shadcn/utils instead of the default $lib/utils), the CLI displays that utils was installed at the default path even though it was actually placed in the correct custom location.

Example from the issue:

  • User configures utils path: $lib/features/shared/components/_shadcn/utils
  • File is correctly installed at: src/lib/features/shared/components/_shadcn/utils.ts
  • But CLI incorrectly shows: ✔ utils installed at src/lib/utils

Root Cause

The display logic in packages/cli/src/utils/add-registry-items.ts calculates the displayed path differently from the actual file path:

  • Actual file path: Calculated by resolveItemFilePath() which has special handling for "utils" item (lines 186-190 in registry/index.ts)
  • Displayed path: Calculated by getItemAliasDir() + item name, which doesn't account for the special utils handling

Solution

Modified the display logic to track and use the actual file path that was written:

  1. Track the first file path written in a new firstFilePath variable
  2. For "utils" item specifically, use this tracked path for the display message
  3. This ensures the displayed path matches the actual location where the file was installed

Changes

Modified Files:

  • packages/cli/src/utils/add-registry-items.ts - Added 11 lines to track and display actual file path
  • packages/cli/test/utils/add-registry-items.test.ts - Added 57 lines with new test case, fixed Windows path compatibility

Code Changes:

// Track the actual file path that was written
let firstFilePath: string | undefined;
for (const file of item.files) {
    let filePath = registry.resolveItemFilePath(opts.config, item, file);
    // ... write file ...
    if (!firstFilePath) {
        firstFilePath = filePath;
    }
}

// Use it for display
if (item.name === "utils" && firstFilePath) {
    const itemPath = path.relative(cwd, firstFilePath);
    return `${highlight(item.name)} installed at ${color.gray(itemPath)}`;
}

Testing

  • ✅ All 147 tests passing (added 1 new test)
  • ✅ TypeScript type checking passes
  • ✅ Prettier formatting applied
  • ✅ ESLint checks pass
  • ✅ Test added for custom utils path scenario
  • ✅ Fixed Windows test failure by normalizing paths with toPosixPath helper

Impact

  • Minimal change: Only affects the display message for utils item
  • No breaking changes: Actual file installation logic unchanged
  • Backward compatible: Works with both default and custom paths
  • Cross-platform: Tests now work on Windows, Linux, and macOS
  • Improved UX: Users now see the correct path where utils was installed

Before & After

Before the fix:

✔ utils installed at src/lib/utils

(Even when installed at src/lib/features/shared/components/_shadcn/utils.ts)

After the fix:

✔ utils installed at src/lib/features/shared/components/_shadcn/utils.ts

(Shows the actual path where the file was installed)

Original prompt

This section details on the original issue you should resolve

<issue_title>bug: when initializing shadcn, cli logs the wrong path for utils file</issue_title>
<issue_description>### Describe the bug

When I initialize shadcn in my project, normally I don't use the standard paths that the CLI provides. In this case, I've used a different one for the Shadcn utils file.

At the end of the process, the CLI shows where the utils file were placed, but, even thought it was placed in the correct path, it says that it was placed in the default path (src/lib/utils).

NOTE: I am willing to open a PR to address this issue

Reproduction

I've just tried to initialize Shadcn and noticed this bug. You can see the step by step process in the screenshot below:

Image

Logs

System Info

System:
    OS: Linux 6.12 Manjaro Linux
    CPU: (12) x64 AMD Ryzen 5 5600G with Radeon Graphics
    Memory: 8.55 GB / 13.52 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.16.0 - ~/.nvm/versions/node/v22.16.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.16.0/bin/npm
    pnpm: 10.12.4 - ~/.local/share/pnpm/pnpm
  npmPackages:
    @lucide/svelte: ^0.544.0 => 0.544.0
    @sveltejs/kit: ^2.22.0 => 2.43.5
    svelte: ^5.0.0 => 5.39.6
    tailwindcss: ^4.0.0 => 4.1.13

Severity

annoyance</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #2307

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@changeset-bot
Copy link

changeset-bot bot commented Oct 5, 2025

🦋 Changeset detected

Latest commit: c10e8f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
shadcn-svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI changed the title [WIP] bug: when initializing shadcn, cli logs the wrong path for utils file fix: display correct path for utils file during init Oct 5, 2025
Copilot AI requested a review from huntabyte October 5, 2025 23:04
Copilot finished work on behalf of huntabyte October 5, 2025 23:04
@huntabyte huntabyte requested a review from AdrianGonz97 October 5, 2025 23:06
@huntabyte
Copy link
Owner

@copilot fix the failing windows tests.

Copy link
Author

Copilot AI commented Oct 6, 2025

@copilot fix the failing windows tests.

Fixed in commit 8aa3e7e. The test was failing on Windows because it expected paths with forward slashes, but Windows uses backslashes. I've updated the test to use the toPosixPath helper (already used in other tests) to normalize paths for cross-platform compatibility.

Copilot finished work on behalf of huntabyte October 6, 2025 13:56
@huntabyte huntabyte marked this pull request as ready for review October 15, 2025 23:14
@github-actions
Copy link
Contributor

github-actions bot commented Oct 15, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
shadcn-svelte ✅ Ready (View Log) Visit Preview c10e8f8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: when initializing shadcn, cli logs the wrong path for utils file

2 participants